﻿using Models.Entities;
using Serilog;
using Services.Equ.PcapCommunication.Abstract;
using SharpPcap;
using SharpPcap.WinDivert;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace Services.Equ.PcapCommunication
{
    /// <summary>
    /// 编辑设备的网络信息操作 (此类不能单独使用，必须先使用ConnnetComunication类建立连接)
    /// </summary>
    public class EditNetworkInfoCommunication : AbstractNormalCommunication
    {
        public required EquInfo EquInfo { get; set; }
        public EditNetworkInfoCommunication(PhysicalAddress destinationMac, string password, ILiveDevice device) : base(destinationMac, password, device)
        {
            DcpType = 0x50005;
            OpType = 5;
            OptionType = 6;
        }
        public override byte[] GetPayload()
        {
            return base.GetPayload();
        }
        public override byte[] CreateBlockData()
        {
            byte[] data = [
                ..IPAddress.Parse(EquInfo.Ip!).GetAddressBytes(),
                ..IPAddress.Parse(EquInfo.Mask!).GetAddressBytes(),
                ..IPAddress.Parse(EquInfo.GateWay!).GetAddressBytes(),
                ..BitConverter.GetBytes(EquInfo.Vlan??0).Reverse(),
                ..BitConverter.GetBytes(EquInfo.IpRole).Reverse()
                ];
            return data;
            //return [
            //    ..BitConverter.GetBytes(OptionType).Reverse(),
            //    ..BitConverter.GetBytes(data.Length).Reverse(),
            //    ..data
            //    ];
        }
    }
}
